Quote Originally Posted by Alexius Lim View Post
and is there any other way to sort my list according to the shipping price or at least make the code shown simpler?
The code is not sorting a list, it's creating a list in sorted order by inserting a node into the list one at a time. It's not the fastest method since on average it traverses through 1/2 of the list for each insertion, but it is simple enough.

There is a faster method for doing this, but it takes a bit more memory. You'll need an array of list structures where each list contains 2^n nodes, plus one temp list. Instead of inserting into a single list, the nodes are stored into a single node list, then any existing lists are merged into ever larger lists until an empty list or the last list is found in the array, where the merged list is stored. This is how the standard template library in C++ implements a list sort in the case of Visual Studio.

Another alternative, is to just append to a list, resulting in an unsorted list, then generate an array of pointers to all the nodes, then sort the list using the pointers using whatever sort algorithm you like. It's a bit of a cheat though and again takes more memory (one pointer per node).